﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BAL;
using Common;
using Entity;
using System.Text;
namespace Web
{
    public partial class StatisticsDetail : System.Web.UI.Page
    {
        protected string DataString = "";
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!UserValidate.CheckLogin(base.Request, "Statistics"))
            {
                base.Response.Write("<script type=\"text/javascript\">top.location.href='login.aspx';</script>");
                base.Response.Redirect("login.aspx");
                base.Response.End();
            }
            DateTime? nullable = null;
            if (!PageValidate.QueryStringIsEmpty("StartDate") && PageValidate.IsDateTime(PageValidate.QueryString("StartDate")))
            {
                nullable = new DateTime?(DateTime.Parse(PageValidate.QueryString("StartDate")));
            }
            DateTime? nullable2 = null;
            if (!PageValidate.QueryStringIsEmpty("EndDate") && PageValidate.IsDateTime(PageValidate.QueryString("EndDate")))
            {
                nullable2 = new DateTime?(DateTime.Parse(PageValidate.QueryString("EndDate")));
            }
            int subjectId = 0;
            if (!PageValidate.QueryStringIsEmpty("SubjestId") && PageValidate.IsNumber(PageValidate.QueryString("SubjestId")))
            {
                subjectId = int.Parse(PageValidate.QueryString("SubjestId"));
            }
            int statusId = 0;
            if (!PageValidate.QueryStringIsEmpty("StatusId") && PageValidate.IsNumber(PageValidate.QueryString("StatusId")))
            {
                statusId = int.Parse(PageValidate.QueryString("StatusId"));
            }
            this.GetDataString(nullable, nullable2, subjectId, statusId);

        }
        private void GetDataString(DateTime? _StartDate, DateTime? _EndDate, int SubjectId, int StatusId)
        {
            IList<QuestionStatusInfo> source = Question.GetQuestionDic(_StartDate, _EndDate, SubjectId, StatusId);
            if (source.Count == 0)
            {
                this.DataString = "";
            }
            else
            {
                IList<string> list2 = new List<string>();
                IList<int> list3 = new List<int>();
                using (IEnumerator<QuestionStatusInfo> enumerator = source.GetEnumerator())
                {
                    Func<string, bool> predicate = null;
                    Func<int, bool> func2 = null;
                    QuestionStatusInfo item;
                    while (enumerator.MoveNext())
                    {
                        item = enumerator.Current;
                        if (item.PrinterId == 0)
                        {
                            if (predicate == null)
                            {
                                predicate = delegate(string t)
                                {
                                    return t == item.Printer;
                                };
                            }
                            if (list2.Where<string>(predicate).Count<string>() == 0)
                            {
                                list2.Add(item.Printer);
                            }
                        }
                        else
                        {
                            if (func2 == null)
                            {
                                func2 = delegate(int t)
                                {
                                    return t == item.PrinterId;
                                };
                            }
                            if (list3.Where<int>(func2).Count<int>() == 0)
                            {
                                list3.Add(item.PrinterId);
                            }
                        }
                    }
                }
                IList<UserStatusInfo> userDic = UserLinkExtend.GetUserDic(list3);
                StringBuilder builder = new StringBuilder();
                using (IEnumerator<UserStatusInfo> enumerator2 = userDic.GetEnumerator())
                {
                    Func<QuestionStatusInfo, bool> func3 = null;
                    UserStatusInfo Item;
                    while (enumerator2.MoveNext())
                    {
                        Item = enumerator2.Current;
                        builder.Append("<tr>");
                        builder.Append("<td>");
                        builder.Append(Item.Name);
                        builder.Append("</td>");
                        builder.Append("<td>");
                        builder.Append(Item.Tel);
                        builder.Append("</td>");
                        builder.Append("<td>");
                        builder.Append(Item.IdCard);
                        builder.Append("</td>");
                        builder.Append("<td>");
                        if (func3 == null)
                        {
                            func3 = delegate(QuestionStatusInfo t)
                            {
                                return t.PrinterId == Item.Id;
                            };
                        }
                        builder.Append(source.Where<QuestionStatusInfo>(func3).Count<QuestionStatusInfo>());
                        builder.Append("</td>");
                        builder.Append("</tr>");
                    }
                }
                using (IEnumerator<string> enumerator3 = list2.GetEnumerator())
                {
                    Func<QuestionStatusInfo, bool> func4 = null;
                    string Item;
                    while (enumerator3.MoveNext())
                    {
                        Item = enumerator3.Current;
                        builder.Append("<tr>");
                        builder.Append("<td>");
                        builder.Append(Item);
                        builder.Append("</td>");
                        builder.Append("<td>未填写</td>");
                        builder.Append("<td>未填写</td>");
                        builder.Append("<td>");
                        if (func4 == null)
                        {
                            func4 = delegate(QuestionStatusInfo t)
                            {
                                return (t.PrinterId == 0) && (t.Printer == Item);
                            };
                        }
                        builder.Append(source.Where<QuestionStatusInfo>(func4).Count<QuestionStatusInfo>());
                        builder.Append("</td>");
                        builder.Append("</tr>");
                    }
                }
                this.DataString = builder.ToString();
            }
        }
    }
}
